package com.yan.test.work.testpaging3;

import android.content.Context;
import android.widget.Toast;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.yan.test.work.testpaging3.net.callback.IOnLoadListener;

import java.util.List;

/**
 * Create By : 'YWY'
 * On : 2024/4/2
 */
public class MainViewModel extends ViewModel {

    private final MainApi mainApi;
    public MutableLiveData<List<DataBean>> resultDataList = new MutableLiveData<>();
    public MutableLiveData<List<DataBean>> loadDataList = new MutableLiveData<>();

    public MainViewModel() {
        mainApi = new MainApi();

    }

    public void queryDataList(Context ctx , String keyWrod , int dataFrom){

        mainApi.queryData(ctx, keyWrod,dataFrom, 20 ,new IOnLoadListener<DataBean>() {
            @Override
            public void onSuccess(List<DataBean> responseList) {
                resultDataList.postValue(responseList);
            }

            @Override
            public void onFailure(String errorMessage) {
                Toast.makeText(ctx, errorMessage, Toast.LENGTH_SHORT).show();
            }

        });

    }

    public void loadDataList(Context ctx , String keyWrod , int dataFrom){
        mainApi.queryData(ctx, keyWrod,dataFrom, 20 ,new IOnLoadListener<DataBean>() {
            @Override
            public void onSuccess(List<DataBean> responseList) {
                loadDataList.postValue(responseList);
            }

            @Override
            public void onFailure(String errorMessage) {
                Toast.makeText(ctx, errorMessage, Toast.LENGTH_SHORT).show();
            }

        });

    }


}
